package com.briup.estore.dao.impl;

import com.briup.estore.common.pojo.Category;
import com.briup.estore.common.utils.JDBCUtils;
import com.briup.estore.dao.CategoryDao;

import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/8/3 下午3:01
 * @Description 对表【es_category】的数据库操作
 **/

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public List<Category> selectFirstCategory() {
        List<Category> list = JDBCUtils.findMany("SELECT id,name,description FROM es_category where parent_id is null;", Category.class);
        return list;
    }

    @Override
    public List<Category> selectByParentId(int parentId) {
        List<Category> list = JDBCUtils.findMany("select id,name,description,parent_id from  es_category where parent_id =?;", Category.class, parentId);
        return list;
    }

    @Override
    public String findNameById(int id) {
        Category category = JDBCUtils.findOne("select name  from es_category where id=?;", Category.class, id);
        return category.getName();
    }
}
